package com.api.shopapi.mapper;

import com.api.shopapi.entity.AccountingRecord;
import com.api.shopapi.entity.dto.AccountingRecordDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface AccountingRecordMapper {

    @Insert("insert into accounting_record (AccountingRecordCode," +
            "BusinessCode," +
            "Price," +
            "Status," +
            "CreateTime) values " +
            "(#{accountingRecord.AccountingRecordCode}," +
            "#{accountingRecord.BusinessCode}," +
            "#{accountingRecord.Price}," +
            "#{accountingRecord.Status}," +
            "#{accountingRecord.CreateTime})")
    int insert(@Param("accountingRecord") AccountingRecord accountingRecord);

    @Update("update accounting_record set BusinessCode=#{accountingRecord.BusinessCode}," +
            "Price=#{accountingRecord.Price}," +
            "Status=#{accountingRecord.Status}," +
            "CreateTime=#{accountingRecord.CreateTime} " +
            "where AccountingRecordCode=#{accountingRecord.AccountingRecordCode}")
    int update(@Param("accountingRecord") AccountingRecord accountingRecord);

    @Delete("delete from accounting_record where AccountingRecordCode=#{accountingRecordCode}")
    int delete(@Param("accountingRecordCode") String accountingRecordCode);

    @Select("select * from accounting_record where AccountingRecordCode=#{accountingRecordCode} limit 1")
    AccountingRecord getByAccountingRecordCode(@Param("accountingRecordCode") String accountingRecordCode);

    @Select("<script>" +
            "select * from accounting_record where 1=1 " +
            "<if test =' businessCode !=null and businessCode !=\"\" '>" +
            " and BusinessCode=#{businessCode} "+
            "</if>" +
            "<if test =' status !=-1 '>" +
            " and Status=#{status} " +
            "</if>" +
            "and CreateTime between #{startTime} and #{endTime} " +
            "order by CreateTime desc" +
            "</script>")
    List<AccountingRecordDTO> getPage(@Param("businessCode") String businessCode, @Param("startTime")String startTime, @Param("endTime")String endTime, @Param("status")int status);
}
